package com.shm.baidu;

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int n = Integer.parseInt(s);
        String str = in.nextLine();
        char[] chars = str.toCharArray();
        int length = chars.length;
        char aChar = chars[length - 1];
        char b = chars[length - 2];
        int min =0;
        int index=0;
        for (int i = 0; i < length; i++) {
            if (chars[i]==aChar){
                index=i;
                break;
            }
        }
        min = index;
        for (int i = 1; i < index; i++) {
            for (int j = 0; j < length; j++) {
                if (chars[j]==chars[length-i-1]){
                    if (j+i<min){
                        min=j+i;
                    }
                    break;
                }
            }
        }
        System.out.println(min+1);
    }
}